package leetcode6

func convert(s string, numRows int) string {
	if numRows == 1 {
		return s
	}

	var res string

	flag := false
	temp := make([]string, numRows)
	idx := 0
	for _, b := range s {
		temp[idx] += string(b)

		if idx == 0 || idx == numRows-1 {
			flag = !flag
		}
		if flag {
			idx++
		} else {
			idx--
		}
	}
	for _, s2 := range temp {
		res += s2
	}
	return res
}
